<?php
require_once "../config/control.php";
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/PHPMailer/class.phpmailer.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/util/Util.php';

mb_internal_encoding('UTF-8');
//error_reporting(E_ALL);
error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail  = new PHPMailer();

$toEmail = $_POST['email'];
$account = $toEmail;
$key	 = Util::encrypt($_POST['password']);
$token 	 = $_POST['token'];

$body = "
<body>
哈囉 , 親愛的貴賓<br />
歡迎成為貓貓狗狗 APP 的一員<br />
請點擊以下連結，完成會員認證手續<br />
<br />
<a href='http://220.132.114.85/bloodPet/view/front/emailVarResult.php?account=$account&key=$key&check=$token'>
官網認證連結
</a><br />
<br />
感謝您  貓貓狗狗 APP 全體人員敬上<br />
此為認證信專用信箱，請勿直接回覆!
</body>
";

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "ssl://smtp.gmail.com"; 	// SMTP server
//$mail->SMTPDebug  = 2;                     	// enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth   = true;                  		// enable SMTP authentication
$mail->SMTPSecure = "ssl";                 		// sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      		// sets GMAIL as the SMTP server
$mail->Port       = 465;                   		// set the SMTP port for the GMAIL server
$mail->Username   = MAIL_USER_NAME;  	// GMAIL username
$mail->Password   = MAIL_PASSWORD;            		// GMAIL password

//寄件人信箱&標題  , 回覆至
$mail->SetFrom("petblood.service@gmail.com", mb_encode_mimeheader('貓貓狗狗 APP 認證信', 'UTF-8'));

//回信信箱&名字
//$mail->AddReplyTo("love9473@yahoo.com.tw","First Last");

//信件標題
$mail->Subject = mb_encode_mimeheader("貓貓狗狗 APP 認證信", "UTF-8");

//附加信件
//$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

//內容顯示格式
$mail->MsgHTML($body);

//收件人信箱&名字
$mail->AddAddress($toEmail, $name);

//附加檔案
//$mail->AddAttachment("images/phpmailer.gif");      // attachment


echo $mail->Send() ? 1 : 0;

?>

